package cn.tedu.smartos.elderly.controller;

import cn.tedu.smartos.base.response.JsonResult;
import cn.tedu.smartos.elderly.pojo.dto.ElderlyAddParam;
import cn.tedu.smartos.elderly.pojo.dto.ElderlyUpdateParam;
import cn.tedu.smartos.elderly.pojo.dto.MedicationAddParam;
import cn.tedu.smartos.elderly.pojo.dto.MedicationUpdateParam;
import cn.tedu.smartos.elderly.pojo.vo.ElderlyVO;
import cn.tedu.smartos.elderly.pojo.vo.MedicationReminderVO;
import cn.tedu.smartos.elderly.service.ElderlyService;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "04.老人模块")
@Slf4j
@RestController
@RequestMapping("/api/v1/elderly/")
public class ElderlyController {
    @Autowired
    private ElderlyService elderlyService;

    /**
     * 01个人信息管理
     */
    @ApiOperation("查看老人信息")
    @ApiOperationSupport(order = 10)
    @GetMapping("getInfo")
    public JsonResult getInfo(Long userId) {
        log.debug("开始处理【查看老人信息】的请求,参数{}",  userId);
        ElderlyVO elderlyVO = elderlyService.getInfo(userId);
        return JsonResult.ok(elderlyVO);
    }
    @ApiOperation("添加老人信息")
    @ApiOperationSupport(order = 20)
    @PostMapping("addInfo")
    public JsonResult createInfo(@RequestBody ElderlyAddParam elderlyCreateParam) {
        log.debug("开始处理【创建老人信息】的请求,参数{}", elderlyCreateParam);
        elderlyService.addInfo(elderlyCreateParam);
        return JsonResult.ok();
    }
    @ApiOperation("修改老人信息")
    @ApiOperationSupport(order = 30)
    @PostMapping("updateInfo")
    public JsonResult updateInfo(@RequestBody ElderlyUpdateParam elderlyUpdateParam) {
        log.debug("开始处理【修改老人信息】的请求,参数{}", elderlyUpdateParam);
        elderlyService.updateInfo(elderlyUpdateParam);
        return JsonResult.ok();
    }

//——————————————————————————————————————————————————————————————————————————

    /**
     * 02紧急呼叫
     */
    @ApiOperation("紧急呼叫")
    @ApiOperationSupport(order = 100)
    @PostMapping("emergencyCall")
    public JsonResult emergencyCall(){
        return JsonResult.ok();
    }

//——————————————————————————————————————————————————————————————————————————
    /**
     * 03用药提醒
     */
    @ApiOperation("用药提醒列表")
    @ApiOperationSupport(order = 200)
    @GetMapping("medicineReminder")
    public JsonResult medicineReminder(@RequestParam Long elderlyUserId,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize){
        log.debug("开始处理【查看老人用药提醒】的请求,参数{},{},{}", elderlyUserId, pageNum, pageSize);
        PageInfo<MedicationReminderVO> list = elderlyService.medicineReminder(elderlyUserId, pageNum, pageSize);
        return JsonResult.ok(list);
    }
    @ApiOperation("用药提醒详情")
    @ApiOperationSupport(order = 210)
    @GetMapping("medicineReminder/detail")
    public JsonResult medicineReminderDetail(@RequestParam Long reminderId){
        log.debug("开始处理【查看老人用药提醒详情】的请求,参数{}", reminderId);
        MedicationReminderVO detail = elderlyService.medicineReminderDetail(reminderId);
        return JsonResult.ok(detail);
    }
    @ApiOperation("删除用药提醒")
    @ApiOperationSupport(order = 220)
    @PostMapping("medicineReminder/delete")
    public JsonResult deleteMedicineReminder(@RequestBody List<Long> reminderIds){
        log.debug("开始处理【删除用药提醒】的请求,参数{}", reminderIds);
        elderlyService.deleteMedicineReminder(reminderIds);
        return JsonResult.ok();
    }
    @ApiOperation("添加用药提醒")
    @ApiOperationSupport(order = 230)
    @PostMapping("medicineReminder/add")
    public JsonResult addMedicineReminder(@RequestBody MedicationAddParam addParam){
        log.debug("开始处理【添加用药提醒】的请求,参数{}", addParam);
        elderlyService.addMedicineReminder(addParam);
        return JsonResult.ok();
    }
    @ApiOperation("修改用药提醒")
    @ApiOperationSupport(order = 240)
    @PostMapping("medicineReminder/update")
    public JsonResult updateMedicineReminder(@RequestBody MedicationUpdateParam updateParam){
        log.debug("开始处理【修改用药提醒】的请求,参数{}", updateParam);
        elderlyService.updateMedicineReminder(updateParam);
        return JsonResult.ok();
    }
}
